{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ebc79e0c",
   "metadata": {},
   "source": [
    "#### 获取网页内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "98ad63c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<h1 class=\"post-title\"><a href=\"http://www.santostang.com/2018/07/15/4-3-%e9%80%9a%e8%bf%87selenium-%e6%a8%a1%e6%8b%9f%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8a%93%e5%8f%96/\">第四章 – 4.3 通过selenium 模拟浏览器抓取</a></h1>\n",
      "<class 'bs4.element.Tag'>\n",
      "第四章 – 4.3 通过selenium 模拟浏览器抓取\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from bs4 import BeautifulSoup\n",
    "\n",
    "link = \"http://www.santostang.com/\"\n",
    "\n",
    "request_headers = {\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'\n",
    "}\n",
    "\n",
    "response = requests.get(link,headers=request_headers)\n",
    "soup = BeautifulSoup(response.text,\"lxml\")\n",
    "\n",
    "h1 = soup.select_one(\"h1.post-title\")\n",
    "\n",
    "print(h1)\n",
    "print(type(h1))\n",
    "print(h1.a.text.strip())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5d4f451",
   "metadata": {},
   "source": [
    "#### 解析HTML 并写入文件"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
